import cv2
cap = cv2.VideoCapture(0)
if not cap.isOpened():
    print("摄像头无效")
    exit()
i = 1
while True:
    ret,frame = cap.read()
    frame = cv2.flip(frame,1)
    if not ret:
        print("摄像头捕捉失败")
        break
    cv2.imshow("capture image",frame)
    key = cv2.waitKey(10)
    if key == 27:
         print("用户按键SCC ，退出")
         break
    elif key == 13:
        cv2.imshow(f"face_{i}.jpg", frame)
        print("成功保存")
        i+=1
cap.release()

